{
LANG : PASCAL
PROB : nuggets
}

program NUGGETS;
const
  fi = 'nuggets.in';
  fo = 'nuggets.out';
  max = 255;
  oo = 2000000001;
var
  a : array[1..25] of longint;
  d : array[0..max] of longint;
  free : array[0..max] of boolean;
  n, res : longint;

procedure inp;
var
  i : integer;
begin
  read(n);
  for i := 1 to n do read(a[i]);
end;

procedure init;
var
  i, j, temp : integer;
begin
  for i := 1 to n do
    for j := i+1 to n do
      if a[i] > a[j] then
      begin
        temp := a[i];
        a[i] := a[j];
        a[j] := temp;
      end;
  d[0] := 0;
  for i := 1 to a[1]-1 do d[i] := oo;
  fillchar(free, sizeof(free), true);
end;

procedure process;
var
  i, u, v, min, temp : longint;
begin
  repeat
    min := oo;
    for i := 0 to a[1]-1 do
      if free[i] and (d[i] < min) then
      begin
        min := d[i];
        u := i;
      end;
    if min = oo then break;
    free[u] := false;
    for v := 1 to n do
    begin
      temp := (u+a[v]) mod a[1];
      if free[temp] and (d[temp]  > d[u] + a[v]) then
                         d[temp] := d[u] + a[v];
    end;
  until false;
end;

procedure solve;
var
  i, j : longint;
begin
  for i := 0 to a[1]-1 do
    if d[i] = oo then
      for j := 2000000000 downto 2000000000-a[1]+1 do
        if d[j mod a[1]] = oo then
        begin
          res := 0;
          exit;
        end;
  res := 0;
  for i := 0 to a[1]-1 do
    if res < d[i]-a[1] then res := d[i]-a[1];
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  init;
  process;
  solve;
  writeln(res);
  close(output);
  close(input);
end.